package com.fanghaoran.view.manager;

import com.fanghaoran.entity.Book;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @Author: win11
 * @Date: 2023/03/28/1:42
 * @Description:
 */
public class BookInfoTableModel extends AbstractTableModel {
    private final String[] columnNames = { "id", "单词书" };
    private final List<Book> bookList;

    public BookInfoTableModel(List<Book> bookList) {
        this.bookList = bookList;
    }

    @Override
    public int getRowCount() {
        return bookList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Book book = bookList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return book.getId();
            case 1:
                return book.getName();
            default:
                return null;
        }
    }



    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }
}
